]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
loginDialog: Support loading banner message from file
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 22 Nov 2024 18:17:44 +0000 (19:17 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 4 Feb 2025 12:10:10 +0000 (13:10 +0100)
Support the new `banner-message-path` and `banner-message-source`
settings, which allows loading the banner message from a path
instead of GSettings. This is mainly useful for `/etc/motd` and
similar mechanisms, to show the same message for both graphical
and non-graphical logins.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3558>

js/gdm/loginDialog.js
js/gdm/util.js

index 125cf299fa583289fa8526f5bb23b5db54a6f068..fa916150260e9db3b3fc3987bfb1d25b6c6ac903 100644 (file)
@@ -46,6 +46,8 @@ const _SCROLL_ANIMATION_TIME = 500;
 const _TIMED_LOGIN_IDLE_THRESHOLD = 5.0;
 const _CONFLICTING_SESSION_DIALOG_TIMEOUT = 60;
 
+Gio._promisify(Gio.File.prototype, 'load_contents_async');
+
 export const UserListItem = GObject.registerClass({
     Signals: {'activate': {}},
 }, class UserListItem extends St.Button {
@@ -508,6 +510,16 @@ export const LoginDialog = GObject.registerClass({
             () => this._updateBanner().catch(logError));
         this._settings.connect(`changed::${GdmUtil.BANNER_MESSAGE_TEXT_KEY}`,
             () => this._updateBanner().catch(logError));
+        this._settings.connect(`changed::${GdmUtil.BANNER_MESSAGE_SOURCE_KEY}`,
+            () => {
+                if (this._updateBannerMessageFile())
+                    this._updateBanner().catch(logError);
+            });
+        this._settings.connect(`changed::${GdmUtil.BANNER_MESSAGE_PATH_KEY}`,
+            () => {
+                if (this._updateBannerMessageFile())
+                    this._updateBanner().catch(logError);
+            });
         this._settings.connect(`changed::${GdmUtil.DISABLE_USER_LIST_KEY}`,
             this._updateDisableUserList.bind(this));
         this._settings.connect(`changed::${GdmUtil.LOGO_KEY}`,
@@ -576,6 +588,8 @@ export const LoginDialog = GObject.registerClass({
         this._bannerLabel.clutter_text.line_wrap = true;
         this._bannerLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
         bannerBox.add_child(this._bannerLabel);
+
+        this._updateBannerMessageFile();
         this._updateBanner().catch(logError);
 
         this._sessionMenuButton = new SessionMenuButton();
@@ -873,13 +887,48 @@ export const LoginDialog = GObject.registerClass({
         this._authPrompt.cancelButton.visible = cancelVisible;
     }
 
+    _updateBannerMessageFile() {
+        const path = this._settings.get_string(GdmUtil.BANNER_MESSAGE_SOURCE_KEY) === 'file'
+            ? this._settings.get_string(GdmUtil.BANNER_MESSAGE_PATH_KEY)
+            : null;
+        const file = path
+            ? Gio.File.new_for_path(path)
+            : null;
+
+        if (!file && !this._bannerMessageFile)
+            return false;
+
+        if (file && this._bannerMessageFile && this._bannerMessageFile.equal(file))
+            return false;
+
+        this._bannerMessageMonitor?.disconnectObject(this);
+        this._bannerMessageMonitor = null;
+
+        this._bannerMessageFile = file;
+
+        if (file) {
+            this._bannerMessageMonitor = file.monitor_file(Gio.FileMonitorFlags.NONE, null);
+            this._bannerMessageMonitor.connectObject(
+                'changed', () => this._updateBanner().catch(logError), this);
+        }
+
+        return true;
+    }
+
     async _getBannerText() {
         const enabled = this._settings.get_boolean(GdmUtil.BANNER_MESSAGE_KEY);
         if (!enabled)
             return null;
 
-        // placeholder
-        await false;
+        if (this._bannerMessageFile) {
+            try {
+                const [contents] = await this._bannerMessageFile.load_contents_async(null);
+                return new TextDecoder().decode(contents);
+            } catch (e) {
+                console.error(`Failed to read banner from ${this._bannerMessageFile.get_path()}: ${e.message}`);
+                return null;
+            }
+        }
 
         return this._settings.get_string(GdmUtil.BANNER_MESSAGE_TEXT_KEY);
     }
index 1e0154f36f0fcb8074abf74f1e1b02a68b6e6bf2..f6b797c32148a64cc920ecf429ff7b04984aae3d 100644 (file)
@@ -33,7 +33,9 @@ export const PASSWORD_AUTHENTICATION_KEY = 'enable-password-authentication';
 export const FINGERPRINT_AUTHENTICATION_KEY = 'enable-fingerprint-authentication';
 export const SMARTCARD_AUTHENTICATION_KEY = 'enable-smartcard-authentication';
 export const BANNER_MESSAGE_KEY = 'banner-message-enable';
+export const BANNER_MESSAGE_SOURCE_KEY = 'banner-message-source';
 export const BANNER_MESSAGE_TEXT_KEY = 'banner-message-text';
+export const BANNER_MESSAGE_PATH_KEY = 'banner-message-path';
 export const ALLOWED_FAILURES_KEY = 'allowed-failures';
 
 export const LOGO_KEY = 'logo';